﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

using CoreSharp.Wp7;

namespace CoreSharp.Keyboard
{
    public class ThaiTextBoxSettings
    {
        public bool PlayValidKeySound { get; set; }

        public bool PlayInvalidKeySound { get; set; }

        /// <summary>
        /// Sound file to play, currently not used
        /// </summary>
        public bool ValidKeySoundFile { get; set; }

        /// <summary>
        /// Sound file to play, currently not used
        /// </summary>
        public bool InvalidKeySoundFile { get; set; }

        public bool VibrateOnValidKey { get; set; }

        public bool VibrateOnInvalidKey { get; set; }
    }

    public class GlobalThaiTextBoxSettings
    {
        private static ThaiTextBoxSettings _Global;

        public static ThaiTextBoxSettings Global
        {
            get
            {
                if (_Global == null)
                {
                    try
                    {
                        if (typeof(ThaiTextBoxSettings).HasSettings("coresharp-thaitextbox"))
                        {
                            _Global = (typeof(ThaiTextBoxSettings)).Load<ThaiTextBoxSettings>("coresharp-thaitextbox");
                        }
                        else
                        {
                            _Global = new ThaiTextBoxSettings()
                            {
                                PlayValidKeySound = true,
                                PlayInvalidKeySound = true,
                                VibrateOnValidKey = true
                            };
                            _Global.Save("coresharp-thaitextbox");
                        }

                        Application.Current.Exit += (s, e) =>
                        {
                            _Global.Save("coresharp-thaitextbox");
                        };
                    }
                    catch (Exception)
                    {
                        _Global = new ThaiTextBoxSettings()
                        {
                            PlayValidKeySound = true,
                            PlayInvalidKeySound = true,
                            VibrateOnValidKey = true
                        };
                    }
                }
                return _Global;
            }
            set
            {
                _Global = value;
            }
            
        }

        public ThaiTextBoxSettings GlobalSetting { get { return GlobalThaiTextBoxSettings.Global; } }

    }
}
